from calibration_absrm import calibration_absrm
from calibration_adjust import calibration_adjust

from calibration_adjust import w_
import numpy as np

def calibration(w,x,tau,method_absrm='TR',method_adj='TR',adj_penalty=1e2,cond_tol=0,verbose = False):
    a,b,sigma,rho,m = calibration_absrm(w,x,method=method_absrm)
    if verbose:
        print('first stage: ',sigma,' ',m)
        print('mse: ',np.sum((w_(x,a,b,sigma,rho,m)-w)**2))
        print('raw params :',a,' ',b,' ',sigma,' ',rho,' ',m)
    out = calibration_adjust(x,a,b,sigma,rho,m,tau,method=method_adj,\
        penalty=adj_penalty,cond_tol=cond_tol,\
        verbose=verbose)
    return out, lambda x: w_(x,out[0],out[1],out[2],out[3],out[4])